﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using MusicHouse.Models;

namespace MusicHouse.Util
{
    public class ControllerBase: Controller
    {
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            Usuario usu = AccountManager.RetornarUsuarioCookie() ?? Session["usuario"] as Usuario;

            if (usu == null)
            {
                var currentControllerName = (string)requestContext.RouteData.Values["controller"];
                var currentActionName = (string)requestContext.RouteData.Values["action"];
                string parametro = Criptografia.Criptografar(string.Format("{0},{1}", currentActionName, currentControllerName), Criptografia.CryptoKey);
                //return RedirectToAction("Index", "Account", new { returnUrl = parametro });
                requestContext.HttpContext.Response.Redirect(string.Format("~/Account?returnUrl={0}", parametro));
            }
            
        }
    }
}